package com.t2t.top;

/**
 * Created by yangpengfei on 2016/4/22.
 * <p/>
 * 线程中的栈深度过长导致如下异常
 * Exception in thread "main" java.lang.StackOverflowError
 */
public class JavaStackDepth {
    private static int stackLength = 1;

    public static int stack(int n) {
        stackLength++;
        if (n == 1) {
            return 1;
        }
        return stack(n - 1) + 1;
    }

    public static void main(String[] args) throws Throwable {
        JavaStackDepth stackDepth = new JavaStackDepth();
        try {
            stackDepth.stack(11420);
            System.out.printf("ok");
        } catch (Throwable e) {
            System.out.println("stack length:" + stackDepth.stackLength);
            throw e;
        }
    }
}
